Location : picowiki » Coding Style
Coding Style
friends
Sometimes, a free function upon a class is the only way to go, even if that function requires internal knowledge of that class.
In that case, ask what is more sane: Exposing a field to the whole world, by making an accessor or the field public, or exposing private and protected data/functions to cherry picked entities only.
In this, friends help to keep proper encapsulation.
Qt Class Header Files
More complex classes (rule of thumb: whose declarations takes up more than 30 lines of code) should follow this pattern:
class Foo: public QWidget { Q_OBJECT // ================== Public =================================================== public: explicit Foo(QWidget *parent = 0); ~Foo(); void setValue (int); int value() const; signals: void valueChanged(); public slots: void changeValue(); // ================== Private ================================================== private: void indicateFoo(); void indicateBar(); private slots: void on_spinBox_valueChanged(int); private: int value_; };
Generally:
- public
- protected
- private
Within each:
- functions
- signals
- slots
Signal-Noise
In the frontend things of picogen, heavy use is made of signals and slots. Here are some rules-of-thumbs regarding the use of them:
- feedback to the user should be given as fast as possible, the user wants it responsive
- anyhow, if an action is invoked as a result of mouse-dragging, the signal-emission should be minimal (e.g., only some spin boxes should be updated), only when the dragging is over, a changed-signal should be emitted to the rest of the program